package com.jg.visitor.kafka.consumer.impl;

import com.jg.visitor.common.bean.WechatInfoBean;
import com.jg.visitor.common.utils.JsonService;
import com.jg.visitor.common.utils.WechatUtils;
import com.jg.visitor.kafka.consumer.KafkaMsgHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component("kafka-topic-wechat")
public class WechatKafkaMsgHandlerImpl implements KafkaMsgHandler {

    @Resource
    private JsonService jsonService;
    @Resource
    private WechatUtils wechatUtils;

    @Override
    public void onMsg(String msg) {
        log.info("msg={}",msg);
        WechatInfoBean bean = jsonService.jsonToObject(msg, WechatInfoBean.class);

        wechatUtils.sendTemplateMsgToApprover(
                bean.getApplyOrderNum(),bean.getUsername(),bean.getOpenId(),bean.getProcessEnum());
        log.info("send wechat msg success...");
    }
}
